﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using KBE_HotFix;

namespace KBE_HotFix.UI
{
    public class World : UIHandler
    {
        private void installEvents()
        {
            // in world
            KBEngine.Event.registerOut("addSpaceGeometryMapping", this, "addSpaceGeometryMapping");
            KBEngine.Event.registerOut("onEnterWorld", this, "onEnterWorld");
            KBEngine.Event.registerOut("onLeaveWorld", this, "onLeaveWorld");
            KBEngine.Event.registerOut("set_position", this, "set_position");
            KBEngine.Event.registerOut("set_direction", this, "set_direction");
            KBEngine.Event.registerOut("updatePosition", this, "updatePosition");
            KBEngine.Event.registerOut("onControlled", this, "onControlled");
        }

        public void addSpaceGeometryMapping(string respath)
        {
            // 这个事件可以理解为服务器通知客户端加载指定的场景资源
            // 通过服务器的api KBEngine.addSpaceGeometryMapping设置到spaceData中，进入space的玩家就会被同步spaceData里面的内容
            Debug.Log("loading scene(" + respath + ")...");
        }

        public void onEnterWorld(Entity entity)
        {
            //if(entity.isPlayer())
            //	return;
            Debug.Log("enter world");
        }

        public void onLeaveWorld(Entity entity)
        {
            //if(entity.renderObj == null)
            //	return;

            //UnityEngine.GameObject.Destroy((UnityEngine.GameObject)entity.renderObj);
            //entity.renderObj = null;
            Debug.Log("leave world");
        }

        public void set_position(Entity entity)
        {
            Debug.Log("set_position");
        }

        public void set_direction(Entity entity)
        {
            Debug.Log("set_direction");
        }

        public void updatePosition(Entity entity)
        {
            Debug.Log("updatePosition");
        }

        public void onControlled(Entity entity, bool isControlled)
        {
            Debug.Log("onControlled");
        }
    }
}
